<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>Cardex - Personal site template</title>
	<script type="text/javascript" src="<?php echo base_url() ?>assets/js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ?>assets/js/jquery-ui.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ?>assets/js/jquery.countdown.js"></script>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/css/jquery.countdown.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/css/student.css" /> 
    
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/themes/cardex/style.css" media="screen">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/themes/cardex/lightbox.css" media="screen">
	<script type="text/javascript" src="<?php echo base_url() ?>assets/themes/cardex/js/jquery.lightbox-0.5.pack.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ?>assets/themes/cardex/js/cufon-yui.js"></script>
	<script type="text/javascript" src="<?php echo base_url() ?>assets/themes/cardex/js/Desyrel_400.font.js"></script>
		
		<!-- Cufon text replacement -->
	<script type="text/javascript">
		$(document).ready(function(){
			Cufon.replace('#about .right ul li');
			Cufon.replace('h2', { textShadow: '0 2px rgba(0, 0, 0, 0.15)' });
			Cufon.replace('#social .right a', {hover:true});
			Cufon.replace('#work .left h3', {hover:true});
			Cufon.replace('h3', { textShadow: '0 2px rgba(0, 0, 0, 0.15)' });
			Cufon.replace('#contactinfo'), {hover:true};
		});
	</script>
	
	<!-- jQuery lightbox -->
	<script type="text/javascript">
		$(document).ready(function(){
			$('#work .right a').lightBox();
		});
	</script>
	
	<!-- Navigation and Content effects -->
	<script type="text/javascript">
		//document.getElementById('problem_skip').click();
		$(document).ready(function(){
			/*
			auto click script
			
			var i = 1;
			var tabInterval = setInterval(function(){
			  $('#problem_skip').trigger('click');
			  i++;
			  if(i > 1){i = 1;}
		   }, 1000);
		   */
						
			var urlpath = $("#base").val() + 'index.php/student/tests/gettotalskip';
			$.ajax({
			  url: urlpath,
			  success: function(data) {
				$("#total_skip_student").html(data);
			  }
			});
					
			var timeLeft = <?=$_SESSION['duration']?>; // 5 minutes
			var timer = window.setInterval(function() {
				timeLeft--;
				var minutesLeft = Math.floor(timeLeft / 60);
				var secondsLeft = timeLeft % 60;
				//console.log('Time left: ' + minutesLeft + ':' + secondsLeft);
				$('#duration').html('Time left: ' + minutesLeft + ':' + secondsLeft);
				if (timeLeft <= 0) {
					window.clearInterval(timer);
					// do some ajax thing
					var urlpath = $("#base").val() + 'index.php/student/tests/done';
					$.ajax({
					  url: urlpath,
					  success: function(data) {
						location.href = urlpath;
					  }
					});
				}
			}, 1000);

			//$('#duration').countdown({until: +<?echo 70?>});
			
			$( "#problem_skip" ).click(function() {
				$( "#problem" ).hide();
				$( "#problem" ).show( "slide",500);
				
				//var urlpath = $("#base").val() + '/' + $("#ppp").val() + '/' + $("#no").val();
				var urlpath = $("#base").val() + 'index.php/student/tests/skip';
				$.ajax({
				  url: urlpath,
				  success: function(data) {
					$("#problem").html(data);
					//alert(urlpath + " " + data);
					//alert('Load was performed.');
				  }
				});
				
			});
			
			$( "#problem_reset" ).click(function() {
				$( "#problem" ).hide();
				$( "#problem" ).show( "slide",500);
				
				//var urlpath = $("#base").val() + '/' + $("#ppp").val() + '/' + $("#no").val();
				var urlpath = $("#base").val() + 'index.php/student/tests/ajax';
				$.ajax({
				  url: urlpath,
				  success: function(data) {
					$("#problem").html(data);
					//alert(urlpath + " " + data);
					//alert('Load was performed.');
				  }
				});
				
			});
			
			//$( "#problem" ).hide();
			$( "#base" ).hide();
		
			$('.page').hide();
			$('#navigation li:first').addClass('active').show();
			$('.page:first').show();
			
			$('#navigation li').click(function(){
				$('#navigation li').removeClass('active');
				$(this).addClass('active');
				
				$('.page').hide();
				var activeTab = $(this).find('a').attr('href');
				$(activeTab).fadeIn('slow');
				return false;
			});
		});
	</script>
	
</head>
<body id="starttest" onload="document.getElementById('problem_reset').click(); javascript:showTotalSkip()">
				
	<input type=hidden id=base value="<? echo base_url() ?>">

	<?
		
		//echo var_dump($test);
		$subject_name = $this->subjects->get_name($test[0]["subject_id"]);
		$info = '';
		foreach($test as $row){
			$info = $row['information'];
		}
		
		$question_arr = array();
		$no=1;
		$data = array();
		
		$temp_question = explode(',',$test[0]['question_id']);
		$temp_percentage = explode(',',$test[0]['percentage']);
		for($i=0; $i<count($temp_question); $i++){
			$rs = $this->tests->get_questions($temp_question[$i], $temp_percentage[$i]);
			foreach($rs as $row){
				array_push($data,$row);
				$no++;
				if($no > $test[0]['total_qty'])
					break;
			}
		}
		
		//shuffle($data);
	
	?>
	<span class=result></span>
	
	
	<? $path = base_url() . "assets/themes/cardex/"; ?> 
	<div id="problemwrap">
		
		<div id="problem_meta_data">
			<table border=10>
			<?
				$search = array("<p>","</p>");
				$test[0]['percentage'] = str_replace($search,"",$test[0]['percentage']);
				$info = str_replace($search,"",$info);
				
				echo "<tr> <td> ". $subject_name . "(" . $info . ")Bahan = " . $test[0]['question_id'] . " </td> </tr>";
				echo "<tr> <td> Komposisi soal = " . $test[0]['percentage'] . "<Br> Total Soal = " . $test[0]['total_qty'] . " </td> </tr>";
				echo "<tr> <td> Durasi = " . $test[0]['duration'] . " </td> </tr>";
				echo "<tr> <td> Skip Digunakan = " . "<span id='total_skip_student'></span> /" . $_SESSION['total_skip_test'] . "  </td></tr>";
			?>
			</table>
		</div>
		<!-- Site content -->

		<div id="problemcontent">
			
			<? echo form_open('student/tests/save'); ?>
			<div id="problem_paper_top">
				<div id="duration">
					
				</div>
				<Br>
				<div id="problem_container">
					<div id="problem"> <? echo "--Tunggu, sedang memuat soal ujian--"; ?> </div>
				</div>

			</div>
			<div id="problem_paper_bottom">
				
			</div>
			
			<div id="error_message"> <?php echo validation_errors(); ?> </div>
				
			<div id="problem_tools">
				<input type="submit" value="Kirim Jawaban" id="problem_submit" name="submit">
				
				<input type="reset" value="Reset Jawaban" id="problem_reset">
				<input type="button" value="Skip" id="problem_skip">
				
			</div>
			<? echo form_close(); ?>
		</div>
		
		<div id="footer">
			<p>Copyright &copy; 2013 Labkom SSP St. Louis 1 </a></p>
		</div>
	</div>
</body>
</html>
